/**
 * Created by wangmeng on 2018/8/17.
 */
var params = new Object();
//页面加载完成回调处理
$(function () {
    setAjaxLoading();
    params.excelCode = excelCode;
});

//导入弹窗确定按钮单击事件处理
function btn_import_ok_click() {
    if ($("#file").val() == "" || $("#file").val() == "undefined") {
        $.alert("default", "info", "请选择文件");
        return false;
    }
    var bcheck = false;
    var filename = $("#file").val();
    var flag = false; //状态
    var arr = ["xls", "xlsx"];
    //取出上传文件的扩展名
    var index = filename.lastIndexOf(".");
    var ext = filename.substr(index + 1);
    //循环比较
    for (var i = 0; i < arr.length; i++) {
        if (ext == arr[i]) {
            bcheck = true; //
            break;
        }
    }
    if (!bcheck) {
        $.alert("default", "info", "文件类型不正确");
        return false;
    }
    $.ajaxFileUpload({
        url: '/common/excelImport/importExcelFile',
        secureuri: false,
        fileElementId: 'file',
        data: params,
        dataType: 'text',
        success: function (data) {
            data = $.parseJSON(data);
            if (data.code != '0000') {
                $.messager.alert("提示", data.msg, "error", function () {
                });
            } else {
                $.messager.alert("提示", data.msg, "info", function () {
                    $("#file").val("");
                    closeLayer();
                });
            }
        },
        error: function (data) {
            $.messager.alert("提示", "导入失败", "info", function () {
            });
        }
    });
}

//下载模板
function btnXls() {
    if (excelCode == "" || excelCode == null) {
        $.messager.alert('操作提示', "未获取到导入编码！", 'info', function () {
        });
        return;
    }
    var url = String.format("/common/excelImport/downloadExcelTemplate?excelCode={0}", excelCode);
    var form = $("#hidden_iframe");
    form.empty();
    form.attr("src", url);
    form.submit();
    var oFrm = $('#hidden_iframe')[0];
    oFrm.onload = oFrm.onreadystatechange = function () {
        return $.alert("default", "info", "该模板已删除或根据导入编码未找到模板");
    }
}

//取消
function btnReset() {
    $("#file").val("");
    closeLayer();
}